//简单一张小图片上传处理

import { reactive,ref } from "vue";
import { Upload,message } from "ant-design-vue";
//import {insertFileUpload} from "@/api/upload";


interface FileItem {
  uid: string;
  name?: string;
  status?: string;
  response?: string;
  url?: string;
  type?: string;
  size: number;
  originFileObj: any;
}

interface FileInfo {
  file: FileItem;
  fileList: FileItem[];
}


class imgUploadClass {

    public imgFile=reactive({
      fileList:[],
      loading:false,
      imageUrl:'',
     })  

    public  beforeUpload = (file: FileItem) => { //上传接口
      const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png';
      if (!isJpgOrPng) {
        message.error('上传的图片格不正确!');
        return false;
      }
      const isLt2M = file.size / 1024 / 1024 < 1;
      if (!isLt2M) {
        message.error('上传图片不能大于1MB!');
        return false;
      }
      this.imgFile.loading = true;
      this.onInsertFileUpload(file);
      return false; //注：我也不知道这个什么坑。。但是这个不能删除;如删除走组件Upload 会报错
    };
 
    public onInsertFileUpload=(file: FileItem)=>{
    //   insertFileUpload({formData:file},res=>{
    //      this.imgFile.imageUrl=res.data; 
    //      this.imgFile.loading = false;
    //  })
    }  
}

export const imgUpload = new imgUploadClass();


  
